package communication;

/**
 * Help signal used for robots to ask assistance from others
 * @author Toar
 */
public class Message 
{
	public enum MessageType { 
		HELP, RESPOND_TO_HELP, ARRIVE_TO_HELP, NOTIFY, I_AM_THE_WINNER, GO_TO_FORCE_POINT, COST, BOX_NOTIFY, BOX_IGNORE, ARE_YOU_ALIVE, I_AM_ALIVE, I_AM_DYING
	}
	
	private String boxID;          // box to be pushed
	private String coordinatorID;  // coordinator (original sender) ID
	private String senderID;       // current sender ID
	
	private MessageType type;
	private int forcePoint;
	private double dist;
	private int cost;
	
	public Message(String boxID, String senderID, String coordinatorID, MessageType type)
	{
		this.boxID = boxID;
		this.senderID = senderID;
		this.coordinatorID = coordinatorID;
		this.type = type;
	}
	
	public Message(String boxID, String senderID, String coordinatorID, MessageType type, int fp)
	{
		this.boxID = boxID;
		this.senderID = senderID;
		this.coordinatorID = coordinatorID;
		this.type = type;
		this.forcePoint = fp;
	}
	
	public String getBoxID() { return boxID; }
	public String getSenderID() { return senderID; }
	public String getCoordinatorID() { return coordinatorID; }
	public MessageType getMessageType() { return type; }
	public int getForcePoint() { return forcePoint; }
	public int getCost() { return cost; }
	public double getDist() { return dist; }
	public void setCost(int c) { cost = c; }
	public void setDist(double c) { dist = c; }
	
	public String toString()
	{
		String message = "";
		switch(type)
		{
		case HELP: 
			message += "HELP";
			break;
		case BOX_IGNORE: 
			message += "BOX_IGNORE";
			break;
		case ARE_YOU_ALIVE: 
			message += "ARE_YOU_ALIVE";
			break;
		case I_AM_ALIVE: 
			message += "I_AM_ALIVE";
			break;
		case I_AM_DYING: 
			message += "I_AM_DYING";
			break;
		case BOX_NOTIFY: 
			message += "BOX_NOTIFY";
			break;
		case RESPOND_TO_HELP:
			message += "RESPOND_TO_HELP";
			break;
		case ARRIVE_TO_HELP:
			message += "ARRIVE_TO_HELP";
			break;
		case I_AM_THE_WINNER:
			message += "I_AM_THE_WINNER";
			break;
		case GO_TO_FORCE_POINT:
			message += "GO_TO_FORCE_POINT " + this.forcePoint;
			break;
		case COST:
			message += "COST " + this.cost;
			break;
		default: 
			message += "UNSPECIFIED";
			break;
		}
		message += ", box " + boxID + ", coord " + (coordinatorID==""? "NO_COORD" : coordinatorID) + ", sender " + senderID;
		return message;
	}
}
